package com.sqznkj.Controller;

import com.sqznkj.Service.ComInfoService;
import com.sqznkj.Service.certificateService;
import com.sqznkj.Service.comIntroService;
import com.sqznkj.entity.certificate;
import com.sqznkj.entity.comInfo;
import com.sqznkj.entity.comIntro;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class adminController {
    @Resource
    ComInfoService service;
    @Resource
    certificateService cs;
    @Resource
    comIntroService comService;
    @RequestMapping("/showpage1")
    public String showpage1(Map<String, Object> map) {

        comInfo comInfo = service.getComInfo();
        comIntro comIntro = comService.getIntro();
        map.put("comInfo", comInfo);
        map.put("comIntro", comIntro);
        return "showpage1";
    }
    @RequestMapping("/showpage3")
    public String showpage3(Map<String, Object> map) {

        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        return "showpage3";
    }
    @RequestMapping("/")
    public String index(Map<String, Object> map) {
        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        return "index";
    }
    @RequestMapping("/index")
    public String index2(Map<String, Object> map) {
        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        return "index";
    }
    @RequestMapping("/anli")
    public String anli(Map<String, Object> map) {
        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        return "anli";
    }
    @RequestMapping("/anli1")
    public String anli1(Map<String, Object> map) {
        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        return "anli1";
    }
    @RequestMapping("/anli2")
    public String anli2(Map<String, Object> map) {
        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        return "anli2";
    }
    @RequestMapping("/zhengshu")
    public String zhengshu(Map<String, Object> map) {
        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        map.put("zs", cs.getzs());
        return "zhengshu";
    }
    @RequestMapping("/zhengshu1")
    public String zhengshu1(Map<String, Object> map) {
        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        map.put("zs", cs.getzz());
        return "zhengshu1";
    }
    @RequestMapping("/call")
    public String call(Map<String, Object> map) {
        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        return "call";
    }
    @RequestMapping("/zhaopin")
    public String zhaopin(Map<String, Object> map) {
        comInfo comInfo = service.getComInfo();
        map.put("comInfo", comInfo);
        return "zhaopin";
    }
    @RequestMapping("/editComInfo")
    public String editComInfo() {
        return "editComInfo";
    }
    @RequestMapping("/ComInfo")
    public String comInfo(String telephone,String Mobilephone,String email,String adress) {
        service.edit(new comInfo(telephone, Mobilephone, email, adress));
        return "adminPage";
    }
    @RequestMapping("/addCi")
    public String addCi(HttpServletRequest request) {
        String[] keys = request.getParameterValues("keys");
        if (keys.length != 0 && keys.length > 1) {
            for (String key : keys) {
                String[] str = key.split("\\|");
                String url = "http://xmsqznkj.com/Ci/" + str[0];
                certificate cer = new certificate(str[1], url, Integer.parseInt(str[2]));
                cs.add(cer);
            }
        } else if (keys.length == 1) {
            String str = keys[0];
            String[] split = str.split("\\|");
            String url = "http://xmsqznkj.com/Ci/" + split[0];
            certificate cer = new certificate(split[1], url, Integer.parseInt(split[2]));
            cs.add(cer);
        } else {
            return "error";
        }
        return "index3";
    }
}
